package junyi.classic.functions;

import junyi.SSAKLog;
import junyi.SSAKObject;
import junyi.card.CardFilter;
import junyi.card.Function;
import junyi.card.FunctionModifier;
import junyi.classic.actions.FinishAttack;
import junyi.classic.player.ClassicPlayer;
import junyi.power.Action;
import junyi.power.ActionChain;
import junyi.power.actions.DamageTargetPlayer;
import junyi.power.actions.TargetPlayerDropSelectedCard;

/**
 * User: Junyi BEI
 * Date: 12-9-30
 * Time: 下午3:02
 */
public class Attack extends Function {
  @Override
  public int ready(SSAKObject... os) {
    return 0;
  }

  @Override
  // card -> player(source) -> player(target)
  public int start(SSAKObject... os) {
    if(os.length != 3) {
      SSAKLog.error("Expect 3 objects: " + os.length);
      return SSAKLog.ERROR;
    }

    ClassicPlayer source = (ClassicPlayer) os[1];
    ClassicPlayer target = (ClassicPlayer) os[2];

    FunctionModifier functionModifier1 = source.functionSourceCheck(this, os);
    FunctionModifier functionModifier2 = target.functionTargetCheck(this, os);
    FunctionModifier functionModifier = functionModifier1.merge(functionModifier2);
    int step = functionModifier.getStartStep();
    int carry = functionModifier.getStartCarry();

    switch(step) {
      case (1):
        Action action1_1 = new FinishAttack(source, Action.ACTION_EXCEPTION, this);
        ActionChain actionChain1 = ActionChain.getActionChain(action1_1, functionModifier, step);
        carry = actionChain1.start(carry);
        step = 2;

      case (2):
        Action action2_1 = new TargetPlayerDropSelectedCard(target, target.getHand(), CardFilter.createCardFilter(CardFilter.EQUALS, new Dodge()), 1, Action.ACCEPT_ANY, this);
        ActionChain actionChain2 = ActionChain.getActionChain(action2_1, functionModifier, step);
        carry = actionChain2.start(carry);
        step = 3;

      case (3):
        Action action3_1 = new DamageTargetPlayer(target, Action.ACTION_FAILURE, this);
        ActionChain actionChain3 = ActionChain.getActionChain(action3_1, functionModifier, step);
        carry = actionChain3.start(carry);
    }

    return carry;
  }
}
